package com.kjzy.service.impl;

import com.kjzy.api.client.UserClient;
import com.kjzy.api.pojo.User;
import com.kjzy.dao.OrderDao;
import com.kjzy.pojo.Order;
import com.kjzy.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderDao orderDao;

//    @Autowired
//    private RestTemplate restTemplate;
    @Autowired
    private UserClient userClient;
    @Override
    public Order getOrderById(Integer id) {
//        查询订单
        Order order=orderDao.getOrderById(id);
//        url路径
//        String url="http://user-service/user/"+order.getUserId();
//     发送http请求，实现远程调用
//        User user = restTemplate.getForObject(url, User.class);
//        使用openfeign实现远程调用
        User user = userClient.getUserById(order.getUserId());
//        封装user到Order
        order.setUser(user);
        return order;
    }

    @Override
    public List<Order> getAllOrders() {
        return orderDao.getAllOrders();
    }
}
